<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/16
 * Time: 13:24
 */

namespace app\admin\model;


class CardUserStock extends DataBase
{
    protected $name = 'card_user_stock';
    protected $autoWriteTimestamp = true;

    public function getDataList()
    {
        $page_config = array(
           'page' => input('get.offset',1),
           'list_rows' => input('get.limit',10),
        );
        $where = [];
        $key = input('key');
        $value = input('value');
        if(!empty($key) && !empty($value)){
            $where[] = ['b.'.$key,'=',$value];
        }
        $order = input('sort','a.id').' '.input('order','a.asc');
        return $this
            ->alias('a')
            ->field('a.*,b.u_id,b.nickname,sum(a.card_num) as sum')
            ->join('users b','a.user_id = b.id','left')
            ->where($where)
            ->group('a.user_id')
            ->order($order)
            ->paginate($page_config);
    }

    public function cardUserStockDetail()
    {
        $user_id = input('get.user_id');
        $page_config = array(
            'page' => input('get.offset',1),
            'list_rows' => input('get.limit',10),
        );
        return $this
            ->alias('a')
            ->field('a.card_num,a.status as a_status,b.id,b.name,b.img,b.status')
            ->join('card b','a.card_id = b.id','left')
            ->where('a.user_id',$user_id)
            ->paginate($page_config);

    }
}